Load imager
plant<- load.image('~/Documents/Github/PhD//imageprocessing/burseragrav1.jpg')
dim(plant)
## [1] 1400 2100 1 3
plot(plant)
## Y-axis shift
imshift(plant,0,50) %>% plot
## X-Axis
imshift(plant,50,0) %>% plot
imshift(plant,50,50) %>% plot
map_il(2:4,~ imresize(plant,1/.)) %>% imappend("x") %>% plot
imrotate(plant,30) %>% plot
grayscale(plant) %>% plot
msk <- px.flood(plant,400,900,sigma=.28) %>% as.cimg
inv<- msk %>%as.data.frame
inv$value<- as.numeric(inv$value==0)
msk<- inv %>% as.cimg()
## Warning in as.cimg.data.frame(.): Guessing image dimensions from maximum
## coordinate values
plot(msk*plant)
indicatorMatrix <-function( test,xrange,yrange,types)
{
if(types=='RBG'){
newtest<- test %>% as.data.frame} else{newtest<-RGBtoHSV(test) %>% as.data.frame}
dfnew<-subset(newtest, x%in%xrange & y%in%yrange) %>% ddply( .(cc),summarize,SD = sd(value, na.rm=TRUE),Mean = mean(value, na.rm=TRUE))
tmp<-subset(newtest,cc==1)
tmp$value<-as.numeric( between (newtest$value[newtest$cc==1] , unlist(dfnew[1,3]-dfnew[1,2]), unlist(dfnew[1,3]+dfnew[1,2]) ) & between ( newtest$value[newtest$cc==2 ] , unlist(dfnew[2,3]-dfnew[2,2]), unlist(dfnew[2,3]+dfnew[2,2]))
& between ( newtest$value[newtest$cc==3] , unlist(dfnew[3,3]-dfnew[3,2]), unlist(dfnew[3,3]+dfnew[3,2])))
newtest$value<- rep(tmp$value,3) *newtest$value
tester<- newtest %>% as.cimg
return(list(tester,tmp,dfnew))
}
samplemat3<- indicatorMatrix(plant,900:1000 ,850:950,'RBG')
## Warning in as.cimg.data.frame(.): Guessing image dimensions from maximum
## coordinate values
#Isolate Leaves
plot(samplemat3[[1]])
#Correlate2D<-function ( A, B ){
# a = ft.fft2(A)
## c = a %*% b
# C = ft.ifft2( c )
# C = ft.fftshift(C)
# return C
#}
#bw <- plant %>% grayscale
#ff <- FFT(bw)
#a=ff %>% as.data.frame
#plot(ff$real,main="Real part of the transform")
samplemathsv<- indicatorMatrix(plant,900:1000 ,850:950,'HSV')
## Warning in as.cimg.data.frame(.): Guessing image dimensions from maximum
## coordinate values
#Isolate Leaves
plot(samplemathsv[[1]])
#Correlate2D<-function ( A, B ){
# a = ft.fft2(A)
## c = a %*% b
# C = ft.ifft2( c )
# C = ft.fftshift(C)
# return C
#}
#bw <- plant %>% grayscale
#ff <- FFT(bw)
#a=ff %>% as.data.frame
#plot(ff$real,main="Real part of the transform")
gray<- grayscale(samplemat3[[1]] )
grayshrink<- shrink(gray,8)
#Isolate Leaves
plot(grayshrink)
#Correlate2D<-function ( A, B ){
# a = ft.fft2(A)
## c = a %*% b
# C = ft.ifft2( c )
# C = ft.fftshift(C)
# return C
#}
#bw <- plant %>% grayscale
#ff <- FFT(bw)
#a=ff %>% as.data.frame
#plot(ff$real,main="Real part of the transform")
gray<- grayscale(samplemat3[[1]] )
graygrow<- grow(gray,2)
#Isolate Leaves
plot(graygrow)
#Correlate2D<-function ( A, B ){
# a = ft.fft2(A)
## c = a %*% b
# C = ft.ifft2( c )
# C = ft.fftshift(C)
# return C
#}
#bw <- plant %>% grayscale
#ff <- FFT(bw)
#a=ff %>% as.data.frame
#plot(ff$real,main="Real part of the transform")
gray<- grayscale(plant )
pcamat<- gray %>% as.data.frame %>% data.table
pcamat2<- data.table::dcast(pcamat,x~y, value.var='value') %>% as.matrix
photo.pca <- prcomp(pcamat2, center = F)
#PCs <- c(round(0.9 * nrow(pcamat2)))
photo<- pcamat2*photo.pca$x[,1]
as.cimg(photo) %>% plot
#Isolate Leaves